/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabox.server;

import java.sql.SQLException;

/**
 *
 * @author rendy
 */
public class Protocol {
    public static int LOGOUT = 0;
    public static int LOGIN = 1;
    public static int BYE = 2;
    
    private int state;
    
    public void process(String[] args) throws SQLException{
        if(args[0].equals("login") && state == LOGOUT){
            if(Database.getSingleton().checkLogin(args[1], args[2]))
                state = LOGIN;
        }
        if(args[0].equals("logout") && state == LOGIN){
            state = BYE;
        }
    }

    String getStatus() {
        switch(state){
            case 0 : return "LOGOUT";
            case 1 : return "LOGIN";
            case 2 : return "BYE";
            default: return "UNKNOWN STATE";
        }
    }
}
